import { useReducer } from 'react';
import { Button } from 'react-vant';
const UseReducerDemo = () => {


    // useState => useReducer是它替代版
    const [count, CountDispatch] = useReducer((state, action) => {
        switch (action) {
            case 'add':
                return state + 1

            case 'sub':
                return state - 1

            default:
                break;
        }
    }, 0)

    return (
        <>
            <h1>{count}</h1>
            <Button onClick={() => CountDispatch('add')}>自增</Button>
            <Button onClick={() => CountDispatch('sub')}>减少</Button>
        </>
    )
}

export default UseReducerDemo